-
-
Notifications
You must be signed in to change notification settings - Fork 40
Conversation
Should be good to go now. Might need to iterate a bit on the pyenv caching – it's better to cache the artefacts in |
with open("tmp/index.html"): | ||
print("great") | ||
|
||
with A() as X: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what the what?
Got a fix coming in a bit. This is all prep for #8. |
src/printer/index.js
Outdated
]); | ||
} | ||
|
||
case "withitem": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no such node type
src/printer/index.js
Outdated
|
||
const n = path.getValue(); | ||
if (n.body.length === 1 && n.body[0].ast_type === "With") { | ||
path.each(p => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this idiomatic? i couldn't find a better way but i might not have looked hard enough
the idea is that body
is an array, but in this case it's of length 1, so we want to call something on it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe:
return concat(
path.map(
p => printPython2With(p, items, print),
"body"
)
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Now I feel embarrassed for not thinking of that. Thanks!
src/printer/index.js
Outdated
@@ -631,6 +631,10 @@ function genericPrint(path, options, print) { | |||
: printPython2With(path, [], print); // Python 2 | |||
} | |||
|
|||
case "withitem": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
never mind
.travis.yml
Outdated
env: | ||
global: | ||
- PYTHON_VERSIONS="2.7.11 3.6.3" | ||
matrix: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this runs a separate build for each version of python under test, rather than a single build that tests both pythons
|
||
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
sys.path.insert(0, os.path.join(base_dir, 'vendor')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen this pattern used elsewhere for CLI-y things where messing with the global Python path isn't a problem. I like that this hides the vendoring details from the caller.
It's also good to split out vendored things from things that are patched from upstream.
if (error) { | ||
throw new Error(error); | ||
function parse(text) { | ||
const executionResult = spawnSync("python", ["-m", "prettier.parser"], { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you get a bit more flexibility when you run something as a module... you can do things like relative imports, which are sorta handy
@@ -1 +1 @@ | |||
run_spec(__dirname, ["python"], { pythonVersion: "3" }); | |||
run_spec(__dirname, ["python"], ">=3.6"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might as well... python 3.5 still sees some use, since it's what some of the active ubuntu LTS versions still ship
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elasticbeanstalk (AWS) is stuck to python 3.4, I'd keep support for 3.4+ if possible
tests_config/run_spec.js
Outdated
const source = read(path).replace(/\r\n/g, "\n"); | ||
|
||
const mergedOptions = Object.assign({}, options, { | ||
parser: parsers[0] | ||
}); | ||
const output = prettyprint(source, path, mergedOptions); | ||
test(`${filename} - ${mergedOptions.parser}-verify`, () => { | ||
expect(raw(source + "~".repeat(80) + "\n" + output)).toMatchSnapshot( | ||
expect(raw(source + "~".repeat(79) + "\n" + output)).toMatchSnapshot( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was a silly change, but 79 makes more sense than 80 if you know it's going to be python code formatted to 79 chars
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should do .repeat(mergedOptions.printWidth)
. FYI I'd like to eventually share this file from Prettier as a package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Merging these would be cool. We'd still have to wrap it for Python to do the version thing, though.
with open("tmp/index.html") as f: | ||
index = f.read() | ||
|
||
with open("tmp/index.html"): | ||
print("great") | ||
|
||
with A() as X: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and as a result of the build changes, we now automatically flag unnecessary 2/3 inconsistencies like these
(this was the only one)
function parse(text) { | ||
const executionResult = spawnSync("python", ["-m", "prettier.parser"], { | ||
env: { | ||
PATH: process.env.PATH, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is so the virtualenv python gets picked up. i don't think we need anything else from env here
install: | ||
- yarn install | ||
before_install: | ||
- export PYTHON_BUILD_CACHE_PATH="/home/travis/.pyenv_cache" | ||
- curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out pyenv is already available on Travis (even when the language is node_js
), and they have a decent selection of versions already installed.
@@ -4,22 +4,19 @@ node_js: | |||
- 6 | |||
- 8 | |||
- 9 | |||
env: | |||
- PYTHON_VERSION=2.7.14 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2.7.14 is the current release here; 2.7.11 is two years old and hasn't been current for a year and a half
'start': token.startpos, | ||
'end': token.endpos, | ||
} | ||
for token in atok.tokens if token.type == tokenize.COMMENT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolves https://github.com/prettier/prettier-python/pull/9/files#r158746577 and correspondingly fixes comment handling in python 2
Any updates here? This PR is unfortunately a mix of a few different things, but I think it sets a lot of pieces in place for further work:
I'd like to use this as a starting point for leveraging existing Python tools to make it easier to handle edge cases here. |
tests_config/run_spec.js
Outdated
@@ -29,16 +39,26 @@ function run_spec(dirname, parsers, options) { | |||
filename[0] !== "." && | |||
filename !== "jsfmt.spec.js" | |||
) { | |||
if (!semver.satisfies(PYTHON_VERSION, versionRange)) { | |||
// Skip each test here with the snapshot name below to avoid obsolete | |||
// snapshot failures. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But they are obsolete, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to clarify the comment a bit.
The idea is that we run the same tests for both Python 2 and Python 3. However, some of these tests can't be run for Python 2.
For those tests, we skip them when the system Python is Python 2 – but if we don't explicitly skip them like this, then they throw off "obsolete snapshot" failures.
Those failures would be correct if we were only dealing with Python 2, but it's more that they're not pertinent to the test suite as currently run.
Any updates here? I can rebase this if we think this is the right approach. |
I'll try to have a good look this weekend, thanks, and sorry for the delay :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taion this is good to go, can you rebase an fix the conflicts? Then I'll merge!
I don't think I'm going to have time to pick up on this again any time soon. Can someone else take over this PR? |
Not planning on doing further work on this. We've switched to Black for the time being anyway. |
Not quite ready to go yet. Need to fix tests.